package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.entity.XlsLogCashEntity;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.dao.XlsLogCashDao;
import io.renren.dto.XlsLogCashDTO;
import io.renren.service.XlsLogCashService;
import io.renren.utils.AppResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 消费明细
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2020-04-12
 */
@Service
public class XlsLogCashServiceImpl extends CrudServiceImpl<XlsLogCashDao, XlsLogCashEntity, XlsLogCashDTO> implements XlsLogCashService {

    @Autowired
    private XlsLogCashDao xlsLogCashDao;

    @Override
    public QueryWrapper<XlsLogCashEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<XlsLogCashEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public XlsLogCashEntity intiLogCash(Integer type, Long fromId, Long userId, String orderNo, BigDecimal preCash, Integer cashType, BigDecimal cash, String remark) {
        XlsLogCashEntity logCash =new XlsLogCashEntity();
        logCash.setType(type);
        logCash.setFromId(fromId);
        logCash.setUserId(userId);
        logCash.setOrderNo(orderNo);
        logCash.setPreCash(preCash);
        logCash.setCashType(cashType);
        logCash.setCash(cash);
        logCash.setRemark(remark);
        logCash.setDataFlag(1);
        logCash.setCreateTime(new Date());
        return logCash;
    }

    @Override
    public AppResult consumption(Long userId, Integer type) {
        List<XlsLogCashEntity> logCash =new ArrayList<>();
        //奖励钱包
        if (type==3){
            logCash = xlsLogCashDao.selectLogCashRewardCash(userId);
        }
        return AppResult.OK(logCash);
    }
}